#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
struct TreeNode
{
    struct TreeNode* left;
    struct TreeNode* right;
    int val;
};
int deepth(struct TreeNode* root)
{
    if (root == NULL)
    {
        return 0;
    }
    return fmax(deepth(root->left), deepth(root->right)) + 1;
}
bool isBalanced(struct TreeNode* root) {
    if (root == NULL)
    {
        return true;
    }
    int h1 = deepth(root->left);
    int h2 = deepth(root->right);
    if (abs(h1 - h2) <= 1)
    {
        return true;
    }
    else
    {
        return false;
    }
    return  isBalanced(root->left) && isBalanced(root->right);
}
struct TreeNode* createnode(int x)
{
    struct TreeNode* newnode = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    newnode->left = NULL;
    newnode->right = NULL;
    newnode->val = x;
    return newnode;
}
struct TreeNode* createtree()
{
    struct TreeNode* node1 = createnode(1);
    struct TreeNode* node2 = createnode(1);
    struct TreeNode* node3 = createnode(1);
    struct TreeNode* node4 = createnode(1);
    struct TreeNode* node5 = createnode(1);
    struct TreeNode* node6 = createnode(1);
    struct TreeNode* node7 = createnode(1);
    node1->left = node2; node1->right = node3;
    node2->left = node4; node3->right = node5;
    node4->left = node6; node5->right = node7;
    return node1;
}
int main()
{
    struct TreeNode* node1 = createtree();
    printf("%d ", isBalanced(node1));
    return 0;
}